added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / CSASPNETCascadingDropDownList / GetDataForCallBack.aspx.cs
blob3fb4f44fa8d025c793c37cdc6358195650cf0c62
1 /****************************** Module Header ******************************\
2 * Module Name: GetDataForCallBack.aspx.cs
3 * Project: CSASPNETCascadingDropDown
4 * Copyright (c) Microsoft Corporation.
5 *
6 * This page is used to retrieve data in callback and write data to client.
7 *
8 * This source is subject to the Microsoft Public License.
9 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
10 * All other rights reserved.
12 * History:
13 * * 7/24/2009 10:33 AM Thomas Sun Created
14 \***************************************************************************/
16 #region Using directives
17 using System;
18 using System.Collections;
19 using System.Configuration;
20 using System.Data;
21 using System.Linq;
22 using System.Web;
23 using System.Web.Security;
24 using System.Web.UI;
25 using System.Web.UI.HtmlControls;
26 using System.Web.UI.WebControls;
27 using System.Web.UI.WebControls.WebParts;
28 using System.Xml.Linq;
29 using System.Collections.Generic;
30 using System.Text;
31 #endregion
34 namespace CSASPNETCascadingDropDownList
36 public partial class GetDataForCallBack : System.Web.UI.Page
38 /// <summary>
39 /// Page Load event
40 /// </summary>
41 /// <param name="sender"></param>
42 /// <param name="e"></param>
43 protected void Page_Load(object sender, EventArgs e)
45 // Get querystring from URL and retrieve data basing on it
46 if (Request.QueryString.Count > 0)
48 string strValue = Request.QueryString[0];
49 if (Request.QueryString["country"] != null)
51 RetrieveRegionByCountry(strValue);
53 else
55 RetrieveCityByRegion(strValue);
61 /// <summary>
62 /// Get region basing on country value
63 /// </summary>
64 /// <param name="strValue">The country value</param>
65 public void RetrieveRegionByCountry(string strValue)
67 List<string> list = RetrieveDataFromXml.GetRegionByCountry(strValue);
68 WriteData(list);
71 /// <summary>
72 /// Get city basing on region value
73 /// </summary>
74 /// <param name="strValue">The region value</param>
75 public void RetrieveCityByRegion(string strValue)
77 List<string> list = RetrieveDataFromXml.GetCityByRegion(strValue);
78 WriteData(list);
81 /// <summary>
82 /// Write data to client
83 /// </summary>
84 /// <param name="list">The list contains value </param>
85 public void WriteData(List<string> list)
87 int iCount = list.Count;
88 StringBuilder builder = new StringBuilder();
89 if (iCount > 0)
91 for (int i = 0; i < iCount - 1; i++)
93 builder.Append(list[i] + ",");
95 builder.Append(list[iCount - 1]);
98 Response.ContentType = "text/xml";
99 // Write data in string format "###,###,###" to client
100 Response.Write(builder.ToString());
101 Response.End();